﻿using System;

namespace MCP.BL.Messages
{
	public class ErrorMessage : MessageBase
	{
		public Exception Exception { get; set; }

		public ErrorMessage(Exception exception)
		{
			Exception innerException = exception.InnerException ?? exception;

			// dig into Exception trace:
			while (innerException.InnerException != null)
			{
				innerException = innerException.InnerException;
			}

			this.Exception = innerException;

		    this.Text = this.Exception.Message;
            this.Priority = MessagePriority.High;
            this.Type = MessageType.Error;
		}

        public ErrorMessage(string message) : base(message, MessagePriority.High, MessageType.Error)
        {
        }
	}
}